package com.example.composestudy.part7

import androidx.compose.animation.Animatable
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay

@Preview(showBackground = true)
@Composable
fun AnimatableTest() {
    val color = remember { Animatable(Color.Red) }
    val ok = remember { mutableStateOf(false) }
    LaunchedEffect(ok) {
        delay(500)
        color.animateTo(if (ok.value) Color.Yellow else Color.Green)
    }
    Box(modifier = Modifier.size(360.dp).background(color.value))
}